import QtQuick
import QtQuick3D
import QtQuick3D.Physics
import "../framework"
import "./ControlComponnet"
import "../Character"

PlayerController{
    id:root

    property alias directionPolicy:directionController.policy

    //角色移动控制

    //移动速度
    property vector3d moveSpeed:Qt.vector3d(200, 600, 200)

    WasdController{
        id:wasdController
        input:root.input
    }

    property TPSCharactor character:pawn

    //计算出移动方位
    property vector3d moveDirection:{
        if(character && input && character.cameraBase){//该计算仅在拥有输入组件的端执行
            let r = character.cameraBase.eulerRotation.y
            let ret = character.cameraBase.mapPositionToNode(character.characterController,wasdController.move)
            return ret
        }
        return Qt.vector3d(0,0,0)
    }

    //计算出移动速度
    property vector3d inputMovement:{
        if(character && input)//该计算仅在拥有输入组件的端执行
        {
            let ret = Qt.vector3d(0,0,0)
            ret.x = moveDirection.x * moveSpeed.x
            ret.y = moveDirection.y * moveSpeed.y
            ret.z = moveDirection.z * moveSpeed.z

            return ret
        }
        return Qt.vector3d(0,0,0)
    }

    onInputMovementChanged: {
        //当输入改变时，将输入的移动赋值给被操控目标
        setPawnProperty("movement",inputMovement)
    }

    //摄像机旋转控制
    ScreenCameraController{
        input:root.input

        cameraBase:character?character.cameraBase:null
        picthBase:character?character.cameraPitchBase:null
    }

    //角色朝向控制
    CharacterDirectionController{
        id:directionController
        cameraDirection:character?character.cameraBase.eulerRotation.y:0//摄像机朝向
        movement:moveDirection//角色移动方位
        onCharacterDirectionChanged: {
            if(character && input)
            {
                setPawnProperty("characterDirection",characterDirection)
            }
        }
    }

    Item {
        id: __materialLibrary__
    }
}
